package com.nbicc.ad.service.impl;

import com.github.pagehelper.Page;
import com.nbicc.ad.mapper.AdCategoryMapper;
import com.nbicc.ad.po.AdCategory;
import com.nbicc.ad.service.IAdCategoryService;
import com.nbicc.common.Const;
import com.nbicc.common.RequestPageObj;
import com.nbicc.common.ResponseObj;
import com.nbicc.parent.serivce.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Author: lilingyan
 * @Date 2018/8/2 10:38
 */
@Service("AdCategoryService")
public class AdCategoryService extends BaseService implements IAdCategoryService {

    @Autowired
    private AdCategoryMapper adCategoryMapper;

    @Override
    public Integer insert(AdCategory adCategory){
        adCategory.setCreateTime(new Date());
        return adCategoryMapper.insert(adCategory);
    }

    @Override
    public AdCategory selectById(Number id){
        return adCategoryMapper.selectById(id);
    }

    @Override
    public Integer updateById(Object adCategory){
        return adCategoryMapper.updateById(adCategory);
    }

    @Override
    public Integer deleteById(Number id) {
        return adCategoryMapper.deleteById(id);
    }

    @Override
    public ResponseObj find(RequestPageObj<Map<String, Object>> requestPageObj) {
        setPageHelper(requestPageObj , AdCategory.TABLE_NEWS_INFO);
        List<AdCategory> adCategoryList = adCategoryMapper.selectByMap(requestPageObj.getData());
        return new ResponseObj(Const.HTTP_STATUS_SUCCESS, adCategoryList, ((Page<?>) adCategoryList).getTotal());
    }

}
